package com.tbq.tbqj_ggl.windows

import android.app.Activity
import android.graphics.Bitmap
import android.view.View
import com.tbq.sdk.L
import com.tbq.sdk.TBQ
import com.tbq.sdk.TBQ_V
import com.tbq.tbqj_ggl.R
import com.tbq.tbqj_ggl.app.AppBasePopupWindow
import com.tbq.tbqj_ggl.app.V
import com.tbq.tbqj_ggl.utils.ScreenUtil
import com.zxy.tiny.Tiny
import java.util.*


/**
 * Created by hais1992 on 2017/4/7/007.
 */

class ScratchGameFailWindows(activity: Activity) : AppBasePopupWindow(activity,
        if (TBQ.get("KEY_IS_MOBILE") == "1") R.layout.mobile_windows_scratch_game_fail else R.layout.windows_scratch_game_fail) {
    private var image_zctz: View? = null
    private var image_lk: View? = null


    override fun showCenter() {
        if (TBQ.get("KEY_IS_MOBILE") != "1") {
            val options = Tiny.FileCompressOptions()
            options.quality = 50    //质量
            options.isKeepSampling = true   //保存默认宽高
            options.outfile = "/sdcard/TBQ_FILE/Screenshot/${TBQ.get(TBQ_V.KEY_RAFFLE_TICKET_ID)}_Game_${TBQ.get("KEY_ADMIN_ID")}.jpg"
            options.config = Bitmap.Config.RGB_565
            Tiny.getInstance().source(ScreenUtil.snapShotWithStatusBar(activity)).asFile().withOptions(options).compress { isSuccess, outfile ->
                L.e("GGL", "图片处理结果：$isSuccess,$outfile")
            }
        }
        super.showCenter()
    }

    override fun drawEnd(v: View) {
        image_zctz = v.findViewById(R.id.image_zctz)
        image_lk = v.findViewById(R.id.image_lk)
        image_zctz!!.setOnClickListener(this)
        image_lk!!.setOnClickListener(this)
        if ("300" != TBQ.get(TBQ_V.KEY_PLAY_GAME)) image_zctz!!.visibility = View.GONE
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.image_lk ->
                //                dismiss();
                //                activity.finish();
                TBQ.openTBQ(activity, false, 0)   //返回并再来一局
            R.id.image_zctz -> {
                dismiss()
                TBQ.openTBQ(activity, false, V.GAME_TYPE)   //返回并再来一局
            }
            else -> super.onClick(view)
        }//  text_start.performClick();
    }
}
